package com.cat.greedyAlgorithm;

import java.util.Arrays;

/**
 * @author 曲大人的喵
 * @description https://leetcode.cn/problems/partition-array-such-that-maximum-difference-is-k/
 * @create 2025/10/9 15:29
 * @since JDK17
 */

public class Solution65 {
    public int partitionArray(int[] nums, int k) {
        Arrays.sort(nums);
        int ans = 1, n = nums.length;
        for (int l = 0, r = 0; r < n; r++) {
            if (nums[r] - nums[l] > k) {
                ans++;
                l = r;
            }
        }

        return ans;
    }
}
